package com.ywyself.controller.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jfinal.handler.Handler;
import com.ywyself.ext.kit.YsHandlerKit;

public class WebResourceHandler extends Handler {

	@Override
	public void handle(String target, HttpServletRequest request, HttpServletResponse response, boolean[] isHandled) {
		// 请求静态网页文件
		boolean allowRequest = true;
		if (target.endsWith(".html")) {
			allowRequest = false;
		} else if (target.endsWith(".jsp")) {
			allowRequest = false;
		} else if (target.endsWith(".asp")) {
			allowRequest = false;
		} else if (target.endsWith(".php")) {
			allowRequest = false;
		} else if (target.endsWith(".htm")) {
			allowRequest = false;
		}
		if (!allowRequest) { // 静态页面请求过滤
			// System.out.println("============================");
			// System.err.println(HttpTools.getRealIp(request) + " try to
			// request a static address. : " + target);
			// System.out.println("============================");
			YsHandlerKit.render403(request, response, isHandled);
			return;
		} else {
			next.handle(target, request, response, isHandled);
		}

		// // 请求不存在的action
		// List<String> listActionKeys = JFinal.me().getAllActionKeys();
		// Pattern p = Pattern.compile(".*\\d+.*");
		// if (listActionKeys.contains(target) || target.contains(".") ||
		// target.contains("/product")
		// || target.contains("catelog") || target.contains("shop")
		// || (listActionKeys.contains(target) && p.matcher(target).matches()))
		// { // 不存在的action请求过滤
		// next.handle(target, request, response, isHandled);
		// return;
		// } else {
		// System.out.println("============================");
		// System.err.println(HttpTools.getRealIp(request) + " try to request
		// non action. : " + target);
		// System.out.println("============================");
		// // next.handle("/err404", request, response, isHandled);
		// next.handle(target, request, response, isHandled);
		// return;
		// }
	}

}
